<?php  
  include("../includes/connect_db.php");
  include("../includes/core.php"); 
?>

<div id="form-modal" class="modal hide fade modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3 id="myModalLabel">
      Modal Header
    </h3>
  </div>
  <div class="modal-body">
    <form class="form-horizontal" data-id="<?php echo $id ?>">
      <div class="row-fluid"> 
        <div class="span12">
          <input type="hidden" class="act" value="<?php echo $act; ?>">
          <div class="alert_container"></div>

          <div>
            <div>
              <div class="alert alert-info">
                <?php 
                  if ($act == "edit") {
                    echo "Perbaharui Travel Agent";
                  } else {
                    echo "Tambah Travel Agent";
                  } 
                ?>
              </div>
              <div class="control-group">
                <label class="control-label">Nama</label>
                <div class="controls">
                  <input placeholder="Masukkan Nama" type="text" name="nama" class="nama required" data-toggle="tooltip" title="Masukkan nama" required value="<?php echo $result_agent[nama] ?>">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label">Komisi</label>
                <div class="controls">
                  <input placeholder="Masukkan Komisi" type="text" name="komisi" class="komisi required" data-toggle="tooltip" title="Masukkan komisi" required value="<?php echo $result_agent[komisi] ?>">
                </div>
              </div>
              <div class="control-group">
                <label class="control-label">Alamat</label>
                <div class="controls">
                  <textarea rows="4" type="text" name="alamat" class="alamat" data-toggle="tooltip" title="Masukkan alamat"><?php echo $result_agent[alamat] ?></textarea>
                </div>
              </div>
              <div class="control-group">
                <label class="control-label">Keterangan</label>
                <div class="controls">
                  <textarea rows="4" type="text" name="keterangan" class="keterangan" data-toggle="tooltip" title="Masukkan keterangan"><?php echo $result_agent[keterangan] ?></textarea>
                </div>
              </div>
              <div class="control-group">
                <label class="control-label">Status</label>
                <div class="controls">
                  <div id="mySwitch" class="make-switch">
                    <?php  
                      if ($result_agent[is_active] == 1) {
                        $checked = "checked";
                      } else {
                        $checked = "";
                      }
                    ?>
                    <input class="is_active" type="checkbox" <?php echo $checked; ?>>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div>
            <div class="span12">
              <ul class="breadcrumb well">
                <button type="submit" class="btn btn-info btn-simpan">
                  <i class="fa fa-check"></i>
                  Simpan
                </button>
              </ul>
            </div>
          </div>
        </div>
      </div>
    </form>

    <div class="footer">
    </div>
  </div>
</div>

<?php include("../includes/footer.php") ?>

<SCRIPT TYPE="text/javascript">
  $(document).ready(function() {
    $('.btn-simpan').click(function(event) {
      event.preventDefault();
      if (validate_form()) {
        act_form = "new";
        act = 1;
        alert_msg = "Data berhasil ditambah";

        if ($('.is_active').is(":checked")) {
          is_active = 1;
        } else {
          is_active = 0;
        };
          
        var tipeUser = {
          id: $('form').data('id'),
          nama: $('.nama').val(),
          keterangan: $('.keterangan').val(),
          alamat: $('.alamat').val(),
          komisi: $('.komisi').val(),
          is_active: is_active,
          act: act,
          act_form: act_form
        }

        $.ajax({
          url: '/action/act_agent.php',
          type: 'POST',
          data: tipeUser,
          cache: false, 
          success: function(data){
            if (data == "sukses") {
              alert(alert_msg);
              window.location.reload();
            } else {
              alert(data);
            }
          }
        })
      }
    });
  });
</SCRIPT>